// pages/pay/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cart: [],
    address: {},
    totalmoney: 0,
    goodsnum: 0,
  },
  onShow() {
    this.getCartList()
    this.getAddress()
  },
  getCartList() {
    let totalmoney = 0;
    let goodsnum = 0;
    const cart1 = wx.getStorageSync("cart") || [];
    const cart = cart1.filter(e => e.checked);

    cart.forEach(e => {
      if (e.checked === true) {
        totalmoney += e.goods_price * e.num,
          goodsnum += e.num
      }
    })
    this.setData({
      cart,
      totalmoney,
      goodsnum
    })
  },
  getAddress() {
    const address = wx.getStorageSync("address");
    this.setData({
      address
    })
  },
  handlePay() {
    wx.showModal({
      title: '提示',
      content: '确认支付吗',

      success: (result) => {
        if (result.confirm) {
          wx.showToast({
            title: '支付成功',
            icon: 'none',
            duration: 1000
          });
          setTimeout(() => {
            const cart1 = wx.getStorageSync("cart");
            const cart = cart1.filter(e => !e.checked)
            wx.setStorageSync("cart", cart);
            wx.navigateBack({
              delta: 1
            });
          }, 1000)




        }
      },

    });

  }
})